const StudentApi = function () {
    const baseUrl = 'http://101.42.178.195:8080/Student';
    return {
        /**
         * 学生注册
         * @param uid
         * @param pwd
         * @returns {Promise<*>}
         */
        async studentRegister(uid, pwd) {
            return await axios.post(`${baseUrl}/Register?uid=${uid}&pwd=${pwd}`)
        },

        /**
         * 获取用户信息
         * @param uid
         * @returns {Promise<*>}
         */
        async getUserInfo(uid) {
            return await axios.get(`${baseUrl}/GetBasicInfo?uid=${uid}`)
        },

        /**
         * 修改用户信息
         * @param uid
         * @param data:{*}
         * @returns {Promise<*>}
         */
        async updateUserInfo(uid, data) {
            return await axios.post(`${baseUrl}/UpdateInfo?uid=${uid}`,data,{
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }, )
        },
        /**
         * 获取学生头像
         * @param uid
         * @returns {Promise<*>}
         */
        async getStudentAvatar(uid) {
            return await axios.get(`${baseUrl}/LoadingPhoto?uid=${uid}`)
        },

        /**
         * 上传学生头像
         * @param uid
         * @param photo:formData
         * @returns {Promise<*>}
         */
        async uploadStudentAvatar(uid, photo) {
            return await axios.post(`${baseUrl}/UploadPhoto?uid=${uid}`, {
                photo
            })
        },

        /**
         * 获取学生头像
         * @param uid
         * @returns {Promise<*>}
         */
        async getUserImage(uid) {
            return await StudentApi.getStudentAvatar(uid).then(res => {
                if (res.data.statusCode === 200){
                    return `data:${res.data.data.contentType};base64,${res.data.data.fileContents}`
                }
            }).catch(err => {
                console.log(err)
                return err;
            })
        }
    }
}();